package com.core.controller;

import com.core.domain.User;
import com.core.resp.AjaxResponse;
import com.core.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import com.core.annotation.OperationLog;

/**
 * @author : HUANG
 * @create : 2025/5/31 22:42
 * @function :
 */
@Api("用户登录")
@RestController
public class LoginController {

    private static final Logger log = LoggerFactory.getLogger(LoginController.class);
    @Autowired
    private LoginService loginService;

    @ApiOperation(value = "登录接口", notes = "验证用户信息登录系统")
    @PostMapping("login")
    @OperationLog(type = "login", module = "auth", description = "用户登录: #user.username")
    public AjaxResponse login(@RequestBody @Validated User user) {
        try {
            return loginService.login(user);
        } catch (Exception e) {
            log.error(e.getMessage());
            return AjaxResponse.error(505, "用户名或密码错误");
        }
    }
    @GetMapping("/test")
    @OperationLog(type = "test", module = "auth", description = "测试接口")
    public AjaxResponse test(){
        return AjaxResponse.success(200,"test success",null);
    }
}
